define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cms/linkcontent/index' + location.search,
                    add_url: 'cms/linkcontent/add',
                    edit_url: 'cms/linkcontent/edit',
                    del_url: 'cms/linkcontent/del',
                    multi_url: 'cms/linkcontent/multi',
                    import_url: 'cms/linkcontent/import',
                    table: 'linkcontent',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cont_title', title: __('Cont_title')},
                        // {field: 'list_order', title: __('List_order'), operate:'BETWEEN'},
//                        {field: 'name', title: __('Name'), operate: 'LIKE'},
//                         {field: 'name', title: __('Name'), align: 'left', formatter:function (value, row, index) {
//                                 return value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
//                             }
//                         },

                        {field: 'cont_description', title: __('Cont_description'), operate: 'LIKE'},
                        {field: 'link', title: __('Link'), operate: 'LIKE'},
//                        {field: 'parent_id', title: __('Parent_id')},
//                        {field: 'post_count', title: __('Post_count')},
//                        {field: 'status', title: __('Status')},
//                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
//                           {field: 'status_text', title:__('Status'), formatter:function (value, row, index) {
//                                   console.log('==',value)
//                             if(value =='隐藏'){
//                                 return  '<span class="text-gray"><i class="fa fa-circle"></i> '+value+'</span>';
//                             }else{
//                                   return  '<span class="text-success"><i class="fa fa-circle"></i> '+value+'</span>';
//                             }
// //                                return value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
//                             }
//                           },
                        {
                            field: 'is_top',
                            title: __('Is_top'),
                            align: 'center',
                            table: table,
                            formatter: Table.api.formatter.toggle
                        },
                       {field: 'parse_time', title: __('Parse_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


//                        {field: 'path', title: __('Path'), operate: 'LIKE'},
//                        {field: 'seo_title', title: __('Seo_title'), operate: 'LIKE'},
//                        {field: 'seo_keywords', title: __('Seo_keywords'), operate: 'LIKE'},
//                        {field: 'seo_description', title: __('Seo_description'), operate: 'LIKE'},
//                        {field: 'is_del', title: __('Is_del')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
